# coding:utf-8
import getopt
import sys
import requests
from xpinyin import Pinyin
import jieba


def get_domains(chars=''):
    print(chars)
    domain = pinyin.get_pinyin(chars).replace('-','')
    domains = ['.com','.cn','.com.cn']

    base_url ="http://panda.www.net.cn/cgi-bin/check.cgi?area_domain="

    s = ''
    for a in domains:
        # print(domain+a)
        s = s + domain + a + ','
        pass
    # print(s[:-1])

    url = "%s%s"%(base_url,s[:-1])
    # print(url)

    r = requests.get(url)

    print(r.text)

    re = str(r.text)

    res = re.replace('\r\n','')[:-1].split("#")
    print(res)
    ss = ""
    for rr in res:
        # print(rr)
        if '211' in rr:
            # print(rr,'已经注册，不可以')
            ss = ss + rr + '已经注册，不可以\n'
        elif '210':
            ss = ss + rr + '还有机会赶快注册去\n'
            # print(rr,'还有机会赶快注册去')
    
    return ss



if __name__ == "__main__":


    pinyin = Pinyin()

    # seg_list = jieba.cut("宋江、卢俊义、吴用、公孙胜、关胜、林冲、秦明、呼延灼、花荣、柴进、李应、朱仝、鲁智深、武松、董平、张清、杨志、徐宁、索超、戴宗、刘唐、李逵、史进、穆弘、雷横、李俊、阮小二、张横、阮小五、张顺、阮小七、杨雄、石秀、解珍、解宝、燕青", cut_all=True) #全模式
    # # print(list(seg_list))


    # rr = list(seg_list)

    aa = "天瑞农业、木香农场、山台子、南山台子、宁夏红、宁钢、tianruigroup"
    rr  = aa.split("、")
    print(rr)
    s = ""
    for aa in rr:
        # print(aa)
        r = get_domains(aa)
        # print(r)
        s = s + r
        pass
    
    with open('nx.txt','w',encoding='utf-8') as f:
        f.write(s)
        pass

